package dk.pun.dums.client.widget;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

import dk.pun.dums.client.event.SystemMessageEventHandler;
import dk.pun.dums.client.event.SystemMessageUpdatedEvent;

public class AdministratorDialog extends DialogBox {

	private static AdministratorDialogUiBinder uiBinder = GWT.create(AdministratorDialogUiBinder.class);

	interface AdministratorDialogUiBinder extends UiBinder<Widget, AdministratorDialog> {}

	@UiField protected transient TextBox message;
	@UiField protected transient Button okButton;
	
	private final transient SystemMessageEventHandler eventHandler;
	
	public AdministratorDialog(final SystemMessageEventHandler eventHandler, final String message) {
		super();
		this.setWidget(uiBinder.createAndBindUi(this));
		this.setText("Administrator");
		this.setAutoHideEnabled(true);
		this.setGlassEnabled(true);

		this.eventHandler = eventHandler;
		this.message.setText(message);
	}

	@UiHandler("okButton")
	public void okButtonClicked(final ClickEvent event) {
		this.eventHandler.onSystemMessageUpdated(new SystemMessageUpdatedEvent(message.getText()));
		this.hide();
	}
	
}
